﻿define([
	'../libs/zepto',
	'../common/yingSoftPrg',
	'../common/dialog',
	'../common/storage',
	'../common/yingSoftCookie',
	'../common/ajax',
	'../doExam/simulatedExamData'
],function(){
	
    var _gDistillTest = new DistillTestData();
    var _defaultConfigJson = {};	//默认配置
    var _testStyleData = [];	//试题类型数组
    var _configJsonData = {};	//配置数据
    var _userConfigJson = {};	//配置数据
    var _selectedConfigID = [];	//会计从业，用户选择的考试科目id
    var _simulated = 0;//标记是否有用户配置，1表明有用户配置，0表明没有用户配置

    var arrCptClassIDs = [];	//用户选择的科目数组（包含了来源、科目）
    var arrCptIDs = [];	//用户选择的科目素组下的章节数组
    var arrStyles = [];	//题型、数量、分值的数组
    var _fanwei = []; // 暂时存储所选的科目;
    var _tiliang = {};
    var myscroll;
    var SrcID = _gDistillTest.getArrSrcID();
    var SbjID = _gDistillTest.getArrSbjID();
    var _flag = 'false';

    for(var i =0; i < SrcID.length; i ++){
    	arrCptClassIDs[i] = {
    		'SourceID':SrcID[i],
    		'SubjectID':SbjID[i]
    	}
    }
    arrCptIDs = _gDistillTest.getArrCptID();
	this.init = function(){
		setCss();
		showContent();
	}
	
	function setCss(){
		var whole_height = window.innerHeight;
		var common_height = $('.common_header').height();
		$('.revise').css('height',whole_height-common_height);
		$('.mock_content').css('height',whole_height-common_height);
	}
	
	// 初始化进入考试的页面(与官方配置的公共部分)
	function setIndex(){
		$('.back').attr('value','0');
		$('.shezhi').css('display','block');
        var str = '<div class="module_content" ></div>';
        $('.mock_content').html(str);
        var log = '<div class="log"></div>';
		$('.module_content').append(log);
		$('.log').css({
			'height':$('.module_content').height()*0.4
		});
		var log_img = '<img src="/images/simulation.png" />';
		$('.log').append(log_img);
		var log_p = '<p><span>严格正规的考试环境，让您无限的自动组卷，通过反复的考试练习，让您了解自己的真实水平</span></p>';
		$('.log').append(log_p);
		var p_height = $('.log p').height()/2;
		$('.log p').find('span').css('line-height',p_height + 'px');
		/* 内容区域 */
		var content = '<div class="content"></div>';
		$('.module_content').append(content);
		$('.content').css('height',$('.module_content').height()*0.6);
    }
	
	// 抽查范围的页面
	function fanwei(){
		$('.nav_list li').eq(0).addClass('curent').siblings().removeClass('curent');
		$('.fanwei').css('display','block');
		$('.tiliang').css('display','none');
		$('.fenzhi').css('display','none');

		_showSubject();	
		
		if(_flag == 'true'){
			for(var i = 0; i < $('.fanwei li').length; i ++){
				$('#selectSub_'+i).attr('flag','defaultImg');
				$('#selectSub_'+i).find('img').attr('src','/images/select.png');
			}
			for(var i = 0; i < _fanwei.length; i ++){
				$('#selectSub_'+_fanwei[i]).attr('flag','selectedImg');
				$('#selectSub_'+_fanwei[i]).find('img').attr('src','/images/selected.png');
			}
		}else{
			if (!_isEmpty(_configJsonData)) {
	            _userConfigJson = JSON.parse(_configJsonData.ConfigJson);
	            _showUserSubject(_userConfigJson);//循环列出备选科目
	       	}
		}
		
		var str1 = '<li>下一步</li><li style="display:none">下一步</li>'+
		    '<li style="display:none;">进入考试</li>';
		$('.step').html(str1);
		
		$('.step li').eq(0).click(function(){
			if (!_isEmpty(_configJsonData)) {
                if (arrCptClassIDs.length === 0 && _userConfigJson.ConfigItems[0].CPTClassIDS.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            } else {
                if (arrCptClassIDs.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            }
            tiliang();
		});
		
		$('.nav_list li').eq(1).click(function(){
			if (!_isEmpty(_configJsonData)) {
                if (arrCptClassIDs.length === 0 && _userConfigJson.ConfigItems[0].CPTClassIDS.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            } else {
                if (arrCptClassIDs.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            }
			tiliang();
		});
		
		$('.nav_list li').eq(2).click(function(){
			if (!_isEmpty(_configJsonData)) {
                if (arrCptClassIDs.length === 0 && _userConfigJson.ConfigItems[0].CPTClassIDS.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            } else {
                if (arrCptClassIDs.length === 0) {
                    G_Prg.alert('请选择抽取科目范围');
                    return;
                }
            }
			fenzhi();
		});

	}
	
	// 题量的页面
	function tiliang(){
		$('.nav_list li').eq(1).addClass('curent').siblings().removeClass('curent');
		$('.fanwei').css('display','none');
		$('.tiliang').css('display','block');
		$('.fenzhi').css('display','none');
		_showTestStyle();
		
		var str1 = '<li style="display:none">下一步</li><li>下一步</li>'+
		    '<li style="display:none;">进入考试</li>';
		$('.step').html(str1);
		
		$('.nav_list li').eq(0).click(function(){
    		fanwei(); 
    		$('.nav_list li').eq(0).addClass('curent').siblings().removeClass('curent');
    		$('.step li').eq(0).css('display','block').siblings().css('display','none');
    	});
    	
    	$('.nav_list li').eq(2).click(function(){
    		fenzhi();
    	});
    	
		$('.step li').eq(1).click(function(){
			localStorage.setItem('num_score',JSON.stringify(_tiliang));
       		fenzhi();
       	});
	}
	
	
	// 分值的页面
	function fenzhi(){
		$('.nav_list li').eq(2).addClass('curent').siblings().removeClass('curent');
		$('.fanwei').css('display','none');
		$('.tiliang').css('display','none');
		$('.fenzhi').css('display','block');
		_showTestScore();
		var str1 = '<li style="display:none">下一步</li><li style="display:none;">下一步</li>'+
		    '<li>进入考试</li>';
		$('.step').html(str1);
		$('.nav_list li').eq(0).click(function(){
    		fanwei();
        });
        $('.nav_list li').eq(1).click(function(){
        	tiliang();
        });
    	
    	// 进入考试
    	$('.step li').eq(2).click(function (){
    		localStorage.removeItem('num_score');
            for (var i = 0; i < _testStyleData.length; i++) {
                //var testScore = G_Prg.$('testScore_' + i);	//试题分值
                if ($('#testScore_' + i).val()) {
                    if (!G_Prg.checkNumber2($('#testScore_' + i).val())) {
                        G_Prg.alert('试题分值必须是数字，请重新输入！');
                        return;
                    }
                    if ($('#testScore_' + i).val() <= 0) {
                        G_Prg.alert('抽取的题型分值必须大于0分，请重新输入！');
                        return;
                    }
                    if ($('#testScore_' + i).val() > 20) {
                        G_Prg.alert('抽取的题型分值最大只能设置20分，请重新输入！');
                        return;
                    }
                }
            }
            _setTypeScore();
            _setConfigName();
        });	//设置试题分数面板下一步单击事件
	}
	
	
	function showContent(){
		var appID = G_Cookie.getAppID();
        if (!appID) {
            G_Prg.throw('程序运行错误，不能处理 testUI._checkInfos: appID=' + appID);
        }
        _defaultConfigJson = _gDistillTest.getDefaultConfig(appID);
        if (_isEmpty(_defaultConfigJson)) {
            _configJsonData = _gDistillTest.getConfigJsonData();
            setIndex();
           /* 进入考试 */
			var startExam = '<div class="startExam">开始考试</div>';
			$('.content').append(startExam);
        } else {
            var appEName = G_Cookie.getAppEName();
            if (appEName === 'CJ_KJCY_DSHYY_BGB' || appEName === 'CJ_KJCY_DSHYY_YTB') {
                _showDefaultConfig_KJCY();
                G_Prg.$('defaultedConfig-KJCY').style.display = 'block';
                G_Prg.$('selectedConfig-KJCY').style.display = 'block';
                G_Prg.$('select-info').style.display = 'none';
            } else {
            	 	setIndex();
            	 	/* 有官方配置的模拟考试 */
            	 	$('.shezhi').css('display','none');
					var config = '<div class="guanfang"><ul></ul</div>'
					$('.content').append(config);
					$('.guanfang').css('height',$('.content').height()*0.8);
                	_showDefaultConfig();
            }
        }
        _setClickEvent();	//设置页面的单击事件
   
	}
	
	function _setClickEvent(){
		// 页面返回
        $('.back').click(function(){
        	if($('.back').attr('value') === '0'){
        		window.location.href = '/doExam-index';
        	}else if($('.back').attr('value') === '1'){
        		setIndex();
        		/* 进入考试 */
				var startExam = '<div class="startExam">开始考试</div>';
				$('.content').append(startExam);
				$('.startExam').click(function(){
					//G_Cookie.setCptID(cptID);
		            var json = {};
		            var id = '';
		            if (!_isEmpty(_configJsonData)) {
		                json = _configJsonData.ConfigJson;
		                id = _configJsonData.SimulationExamRuleID;
		                _simulated = 1;
		            }
		            _configClick(json, id);
		        });	
        	}
		});
		
		// 进入考试
       $('.startExam').click(function(){
            var json = {};
            var id = '';
            if (!_isEmpty(_configJsonData)) {
                json = _configJsonData.ConfigJson;
                id = _configJsonData.SimulationExamRuleID;
                _simulated = 1;
            }
            _configClick(json, id);
        });	
        
        //第一步：点击设置，显示可选择科目
        $('.shezhi').click(function () {
			$('.back').attr('value','1');
        	$('.title').html('修改配置');
			$('.shezhi').css('display','none');
			var str = '<div class="revise"></div>';
			$('.mock_content').html(str);
			var nav_list = '<ul class="nav_list"><li>抽查范围</li>'+
				'<li>题量</li><li>题型分值</li></ul>';
			$('.revise').append(nav_list);  

			var list_content = '<div class="list_content"></div>'
			$('.revise').append(list_content);
			
			
			
			var ullist = '<ul class="fanwei"></ul>';
        	$('.list_content').append(ullist);
        	 
        	var ullist1 = '<ul class="tiliang"></ul>';
        	$('.list_content').append(ullist1);
        	
        	var ullist2 = '<ul class="fenzhi"></ul>';
  			$('.list_content').append(ullist2);
  			
  			var str1 = '<ul class="step"></ul>';
			$('.revise').append(str1); 
			
        	fanwei();
        });	

    }
	
	// 有官方配置的页面
	function _showDefaultConfig() {
        var arrConfigs = _defaultConfigJson;
        var appEName = G_Cookie.getAppEName();
        for (var i = 0; i < arrConfigs.length; i++) {
        		var liTag = document.createElement('li');
		            liTag.id = 'configName_' + i;
		            liTag.className = 'default-btn kj-Btn';
		            liTag.lang = i;
		            liTag.innerHTML = arrConfigs[i].ConfigTitle;
		            liTag.onclick = function () {
		                var configID = arrConfigs[this.lang].DefaultSimulationID;
		                var configJson = arrConfigs[this.lang].ConfigJson;
		                var cptID = JSON.parse(arrConfigs[this.lang].ConfigJson).ConfigItems[0].sbjID;
		                G_Cookie.setCptID(cptID);
		                _simulated = 1;
		                _configClick(configJson, configID, 1);
		            };
		
		           $('.guanfang ul').append(liTag);
        		}
        	}
    
	
	// 从进入考试进入到答题页面
	function _configClick(configJson, configID, flag) {
        if (!G_Storage.checkSessionStorageSupport()) {
            G_Prg.alert('您的浏览器不支持SessionStorage！');
            return;
        }
        G_Storage.setSessionStorageValue('ConfigJSON', configJson);
        window.location.href = '/answerExam?fromUrl=mockExam&configID=' + configID + '&simulated=' + _simulated + '&defaulted=' + flag;
    }
	
	function clickEvent(){
		$('.back').click(function(){
			window.location.href = '/doExam-index';
		});
	}
	
	
	// 获取网址上传递的参数
	function GetQueryString(name){
	 	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	 	var r = window.location.search.substr(1).match(reg);
	 	if(r!=null)return  unescape(r[2]); return null;
	}
	
	
	// 判断对象是否为空
	function _isEmpty(obj) { 
        for (var name in obj) {
            return false;
        }
        return true;
    };
    
    // 显示抽查范围的内容
    function _showSubject() {
    	$('.fanwei').html('');
        var arrShowName = _gDistillTest.getArrShowName();
        for (var i = 0; i < arrShowName.length; i++) {
        	var str = '<li id="selectSub_'+ i +'" value="'+ i +'" flag="selectedImg"><img src="/images/selected.png"/><span>'+ arrShowName[i] +'</span></li>';
            $('.fanwei').append(str);
        }
        // 初始化的arrCptClassIDs
        
        $('.fanwei li').click(function () {
        	_flag = 'true';
            _setSubjectClick(this.id, this.value);
        });
        
    }
    
    // 选择科目范围的单击事件
    function _setSubjectClick(selectSubID, index) {
        var arrNewClassIDs = [];
        var arrNewCptIDs = [];
        var quchong1 = [];
        var quchong2 = [];
        if (!_isEmpty(_configJsonData)) {
        	quchong1 = _userConfigJson.ConfigItems[0].CPTClassIDS;
        	quchong2 = _userConfigJson.ConfigItems[0].CPTIDS;
//      	for (var i = 0; i < quchong1.length-1; i++) {
//      		for(var j = i+1; j < quchong1.length; j++){
//      			if (quchong1[i].SourceID === quchong1[j].SourceID) {
//	                    quchong1.splice(j, 1);
//	                    quchong2.splice(j,1);
//	                }
//      		}
//          }
        	arrNewClassIDs = quchong1;
        	arrNewCptIDs = quchong2;
        } else {
            arrNewClassIDs = arrCptClassIDs;
           	arrNewCptIDs = arrCptIDs;
        }
        var arrShowIndex = _gDistillTest.getArrShowIndex();
        var arrIndex = arrShowIndex[index];
        var arrSrcID = _gDistillTest.getArrSrcID();
        var arrSbjID = _gDistillTest.getArrSbjID();
        var arrCptID = _gDistillTest.getArrCptID();
        //var selectSub = G_Prg.$(selectSubID);
        if ($('#'+selectSubID).attr('flag') ==='defaultImg') {	//勾选科目
        	$('#'+selectSubID).find('img').attr('src','/images/selected.png');
            $('#'+selectSubID).attr('flag','selectedImg');
            for (var i = 0; i < arrIndex.length; i++){
                arrNewClassIDs.push({
                    "SourceID": arrSrcID[arrIndex[i]],
                    "SubjectID": arrSbjID[arrIndex[i]]
                });
                arrNewCptIDs.push(arrCptID[arrIndex[i]]);
            }

        } else if ($('#'+selectSubID).attr('flag') === 'selectedImg') {	//取消科目选择
        	$('#'+selectSubID).attr('flag','defaultImg'); 
            $('#'+selectSubID).find('img').attr('src','/images/select.png')
            for (var i = 0; i < arrNewClassIDs.length; i++) {
                if (arrNewClassIDs[i].SourceID === arrSrcID[arrIndex[0]] && arrNewClassIDs[i].SubjectID === arrSbjID[arrIndex[0]]) {
                    arrNewClassIDs.splice(i, arrIndex.length);
                    arrNewCptIDs.splice(i, arrIndex.length);
                }
            }
        }
        arrCptClassIDs = arrNewClassIDs;
        arrCptIDs = arrNewCptIDs;
        
//      $('.step li').eq(0).click(function(){
//      	if (!_isEmpty(_configJsonData)) {
//              if (arrCptClassIDs.length === 0 && _userConfigJson.ConfigItems[0].CPTClassIDS.length === 0) {
//                  G_Prg.alert('请选择抽取科目范围');
//                  return;
//              }
//          } else {
//              if (arrCptClassIDs.length === 0) {
//                  G_Prg.alert('请选择抽取科目范围');
//                  return;
//              }
//          }
			_fanwei = [];
            for(var i = 0; i < $('.fanwei li').length; i++){
            	if($('#selectSub_'+i).attr('flag') == 'selectedImg'){
            		_fanwei.push(i);
            	}
            }
        //});

    }
    
    // 显示用户已选择的科目
    function _showUserSubject(configJson){
    	var arrClassID = [];
        var quchong1 = configJson.ConfigItems[0].CPTClassIDS;
//      for (var i = 0; i < quchong1.length-1; i++) {
//  		for(var j = i+1; j < quchong1.length; j++){
//  			if (quchong1[i].SourceID === quchong1[j].SourceID && quchong1[i].SubjectID ===quchong1[j].SubjectID) {
//                  quchong1.splice(j, 1);
//              }
//  		}
//      }
		for(var i = 0; i < $('.fanwei li').length; i ++){
			$('#selectSub_' + i).attr('flag','defaultImg');
            $('#selectSub_' + i).find('img').attr('src','/images/select.png');
		}
        arrClassID = quchong1;
        var arrSrcID = _gDistillTest.getArrSrcID();
        var arrSbjID = _gDistillTest.getArrSbjID();
        var arrShowIndex = _gDistillTest.getArrShowIndex();
        for (var i = 0; i < arrClassID.length; i++) { 
            var srcID = arrClassID[i].SourceID;
            var sbjID = arrClassID[i].SubjectID;
            for (var j = 0; j < arrSrcID.length; j++) {//与来源、科目id数组进行匹配，获得索引
                if (srcID === arrSrcID[j] && sbjID === arrSbjID[j]) {
                    for (var k = 0; k < arrShowIndex.length; k++) {//与备选科目的索引数组进行匹配
                        var arrIndex = arrShowIndex[k];
                        for (var m = 0; m < arrIndex.length; m++) {
                            if (arrIndex[m] === j) {
                                $('#selectSub_' + k).attr('flag','selectedImg');
                                $('#selectSub_' + k).find('img').attr('src','/images/selected.png');
                                break;
                            }
                        }
                        
                    } //end arrShowIndex数组循环
                    break;
                } //end if
            } //end arrSrcID数组循环
        } //end arrClassID数组循环
    }
    
    //题量页面
    function _showTestStyle(){
        var userID = G_Cookie.getUserID();
        if (!userID) {
            return;
        }
        var appEName = G_Cookie.getAppEName();
        if (!appEName) {
            return;
        }
        var guid = G_Cookie.getGuid();
        var moren = _gDistillTest.getArrCptID();
        var _morenArr = [];
        for(k = 0; k < moren.length; k ++){
        	for(var m = 0; m < moren[k].length; m ++){
        		_morenArr.push(moren[k][m]);
        	}
        }
        var newArrCptID = [];
        //修改功能，显示用户之前的配置名称
        if (!_isEmpty(_configJsonData)) {
        	arrCptIDs = _userConfigJson.ConfigItems[0].CPTIDS;
            if(arrCptIDs.length == 0){
            	newArrCptID = _morenArr;
            	//arrCptIDs = moren;
            }else{
            	for (var i = 0; i < arrCptIDs.length; i++) {
            		if(arrCptIDs[i] == null){
            			continue;
            		}else{
            			for (var j = 0; j < arrCptIDs[i].length; j++) {
			                newArrCptID.push(arrCptIDs[i][j]);
			            }
            		}
		        }
            }
        }else{
        	newArrCptID = _morenArr;
        }
        
        if(newArrCptID.length==0){
        	$('.tiliang').html('<span>章节试题为空，请重新选择！</span>');
        	$('.tiliang span').css({'width':'100%','display':'block','padding-top':'50px','text-align':'center','font-size':'20px','color':'#737373'});
        	return;
        }
        _testStyleData = _gDistillTest.getTestStyleData(appEName, JSON.stringify(newArrCptID), userID, guid);
        
        for(var i = 0; i < _testStyleData.length; i ++){
        	_tiliang[i] = {};
        	_tiliang[i] = {
        		'type':_testStyleData[i].Type,
        		'num':5,
        		'count':2
        	}
        }
        $('.tiliang').html('');
        for (var i = 0; i < _testStyleData.length; i++) {
        	var str1 = '<li lang="'+ _testStyleData[i].TestCount +'" id="count_'+ i +'" value="'+ _testStyleData[i].StyleID +'"><span id="style_'+ i +'" title="'+ _testStyleData[i].Explain +'">'+ _testStyleData[i].Style.replace(/(^\s+)|(\s+$)/g, "") +'</span>'+
					'<div class="right"><input type="text" id="testStyleCount_'+ i +'" maxLength="3" lang="'+ i +'" class="inputTag ser"/>'+
					'<label>题</label></div></li>';
			$('.tiliang').append(str1);
			if (_testStyleData[i].TestCount < 5) {
                $('.right').eq(i).find('input').attr('value',_testStyleData[i].TestCount);	//设置默认数量
            } else {
                $('.right').eq(i).find('input').attr('value',5);;	//设置默认数量
            }
		}
        
        if(_flag == 'false'){
        	if (!_isEmpty(_configJsonData)) {
	            var arrStyles = _userConfigJson.ConfigItems[1].Styles;
	            for(var i = 0;i < _testStyleData.length; i ++){
	                for (var j = 0; j < arrStyles.length; j++) {
	                  if (arrStyles[j].StyleID == _testStyleData[i].StyleID) {
	                      $('#testStyleCount_' + i).attr('value',arrStyles[j].TestNum);
	                      if(_tiliang.lengthhh > 0){
	                      	  _tiliang[i].num = arrStyles[j].TestNum;
		                      _tiliang[i].count = arrStyles[j].Score;
		                  }
	                  }
	                }
	                
	            }
	        }
        }
        
        var m = '';
        m = JSON.parse(localStorage.getItem('num_score'));
            
        $('.inputTag').blur(function(){
            _checkTestCount(this.id, this.lang, this.placeholder);
        });
        
        if(_flag == 'true'){
        	if(m){
        		for(var i in m){
		        	$('#testStyleCount_' + i).attr('value',m[i].num);
		        }
        	}
        }    
    }
    
    // 显示已设置的题量
    function show_tiliang(){
    	var arrStyles = _userConfigJson.ConfigItems[1].Styles;
        for(var i = 0;i < _testStyleData.length; i ++){
            for (var j = 0; j < arrStyles.length; j++) {
              if (arrStyles[j].StyleID == _testStyleData[i].StyleID) {
                  $('#testStyleCount_' + i).attr('value',arrStyles[j].TestNum);
              }
            }
        }
    }
    
    
    // 判断题量是否合法
    function _checkTestCount(testStyleCountID, index, placeholder){
        if ($('#'+testStyleCountID).val()){
            if (!G_Prg.checkNumber($('#'+testStyleCountID).val())) {
                G_Prg.alert('试题数量必须是整数，请重新输入！');
                return;
            }
        }else{
        	if(_testStyleData[index].TestCount <= 5){
        		$('#'+testStyleCountID).val(_testStyleData[index].TestCount);
        	}else{
        		$('#'+testStyleCountID).val(5);
        	}
        }
        var count = parseInt($('#'+testStyleCountID).val());
        if (count > _testStyleData[index].TestCount || parseInt(placeholder) > _testStyleData[index].TestCount) {
            G_Prg.alert('【' + _testStyleData[index].Style + '】类型在题库中仅有' + _testStyleData[index].TestCount + '题，请重新输入！');
            return;
        } else if (count <= -1) {
            G_Prg.alert('抽取的试题数量不能是负数，请重新输入！');
            return;
        } else if (count > 100) {
            G_Prg.alert('每种题型数量最大只能设置100题，请重新输入！');
            return;
        }
        _tiliang[index].num = $('#'+testStyleCountID).val();
    }
    
    // 题型分值的页面展示
    function _showTestScore() {
    	$('.fenzhi').html('');

    	if(_testStyleData.length == 0){
    		$('.fenzhi').html('<span>章节试题为空，请重新选择！</span>');
        	$('.fenzhi span').css({'width':'100%','display':'block','padding-top':'50px','text-align':'center','font-size':'20px','color':'#737373'});
        	return;
    	}
    	
        for (var i = 0; i < _testStyleData.length; i++){
            var liTag = document.createElement('li');
            liTag.id = 'styleID_' + i;
            liTag.value = _testStyleData[i].StyleID;	//试题的styleID
			
			liTag.lang = _testStyleData[i].Type;	//试题所属Type
            liTag.title = _testStyleData[i].SubType;	//针对A3Test、BTest进行控制
            
            //设置了某种题型数量为0，则在分值设置页面不需要显示了
            if (parseInt($('#testStyleCount_' + i).attr('value')) === 0) {
                liTag.style.display = 'none';
            }
            //设置试题分数输入
            //var pTag2 = document.createElement('p');
            var spanTag3 = document.createElement('span');
            var spanTag4 = document.createElement('label');
            var inputTag2 = document.createElement('input');
            var oDiv = document.createElement('div');
            spanTag3.id = 'style_' + i;
            spanTag3.innerHTML = _testStyleData[i].Style.replace(/(^\s+)|(\s+$)/g, "");
            spanTag3.title = _testStyleData[i].Explain;
            liTag.appendChild(spanTag3);
            
            oDiv.className = 'rightFen';
            liTag.appendChild(oDiv);
            
            inputTag2.type = 'tel';
            inputTag2.title = _testStyleData[i].Type;
            inputTag2.className = 'ser';
            inputTag2.id = 'testScore_' + i;
            inputTag2.lang = i;
            inputTag2.value = '2';	//设置默认数量
            inputTag2.maxLength = '4';
            inputTag2.onblur = function () {
                _checkTestScore(this.id, this.lang, this.value);
            };
            spanTag4.innerHTML = '分';
            oDiv.appendChild(inputTag2);
            oDiv.appendChild(spanTag4);
           
            document.getElementsByClassName('fenzhi')[0].appendChild(liTag);
            
            if(_flag == 'true'){
            	var m = JSON.parse(localStorage.getItem('num_score'));
            	if(m){
            		if(m[i].num == '0'){
            			$('#styleID_' + i).css('display','none');
            		}else{
            			var type = $('#testScore_'+i).attr('title');
	            		for(var n in m){
	            			if(type == m[n].type){
	            				$('#testScore_'+i).val(m[n].count);
	            			}
	            		}
            		}
            	}
            }else{
            	if (!_isEmpty(_configJsonData)) {
	                var arrStyles = _userConfigJson.ConfigItems[1].Styles;
	                for (var j = 0; j < arrStyles.length; j++) {
	                    if (arrStyles[j].StyleID == _testStyleData[i].StyleID) {
	                       $('#testScore_' + i).val(arrStyles[j].Score);
	                    }
	                }
	            }
            }
            
        }
    }
    
    // 检查输入的分值是否合法
    function _checkTestScore(testScoreID, index, placeholder) {
        if ($('#'+testScoreID).val()) {
            if (!G_Prg.checkNumber2($('#'+testScoreID).val())) {
                G_Prg.alert('分值必须是数字，请重新输入！');
                return;
            }
            var score = Number($('#'+testScoreID).val());
            if (score <= 0) {
                G_Prg.alert('抽取的题型分值必须大于0分，请重新输入！');
                return;
            } else if (score > 20) {
                G_Prg.alert('抽取的题型分值最大只能设置20分，请重新输入！');
                return;
            }
        }
        var m = JSON.parse(localStorage.getItem('num_score'));
        var type = $('#'+testScoreID).attr('title');
        for(var i in m){
        	if(m[i].type == type){
        		m[i].count = $('#'+testScoreID).val();
        	}
        }
        localStorage.setItem('num_score',JSON.stringify(m));
    }
    
    // 设置保存试题类型的数量和分值
    function _setTypeScore() {
        for (var i = 0; i < _testStyleData.length; i++) {
            var testStyleCount = $('#testStyleCount_' + i).val();	//试题类型数量
            var testScore = $('#testScore_' + i).val();	//试题分值
            var countValue = '';
            var scoreValue = '';

            //如果用户不进行试题数量、分数值的设置
            if (!testStyleCount) {
                countValue = $('#testStyleCount_' + i).attr('value');
            } else {
                countValue = testStyleCount;
            }
            if (!testScore) {
                scoreValue = $('#testScore_' + i).attr('value');
            } else {
                scoreValue = testScore;
            }
            arrStyles.push({
                "StyleID": $('#styleID_' + i).attr('value'),
                "Explain": $('#style_' + i).attr('title'),
                "Style": $('#style_' + i).html(),
                "Type": $('#styleID_' + i).attr('lang'),
                "SubType": $('#styleID_' + i).attr('title'),
                "TestTotal": $('#count_' + i).attr('lang'),
                "TestNum": countValue,
                "Score": Number(scoreValue)
            });
        }
    }
    
    // 由进入考试进入到考试页面
    function _setConfigName() {
        var userID = G_Cookie.getUserID();
        if (!userID) {
            return;
        }
        var appEName = G_Cookie.getAppEName();
        if (!appEName) {
            G_Prg.throw('程序运行错误，DistillTestUI._setConfigName : appEName = "' + appEName + '",获取数据出现异常');
        }
        var appID = G_Cookie.getAppID();
        if (!appID) {
            G_Prg.throw('程序运行错误，DistillTestUI.appID : appID = "' + appID + '",获取数据出现异常');
        }
        //修改功能
        var configID = '';
//      if (!_isEmpty(_configJsonData)) {
//          configID = _configJsonData.SimulationExamRuleID;
//          arrCptClassIDs = _userConfigJson.ConfigItems[0].CPTClassIDS;
//      }
        //拼接成json
        
        var _m = _gDistillTest.getArrCptID();
        var _n = [];
        if(_fanwei.length > 0){
        	for(var i = 0; i < _fanwei.length; i ++){
        		if(_m[_fanwei[i]] == null){
        			
        		}else{
        			_n.push(_m[_fanwei[i]]);
        		}
	        }
        }else{
        	if(!_isEmpty(_configJsonData)){
        		if(_userConfigJson.ConfigItems[0].CPTIDS.length > 0){
	        		_n = _userConfigJson.ConfigItems[0].CPTIDS;
	        	}else{
	        		_n = _m;
	        	}
        	}else{
        		_n = _m;
        	}
        }
        var jsonObj = {
            "UserID": userID,
            "AppEName": appEName,
            "SimulationExamRuleID": configID,
            "ConfigTitle": '模拟考场',
            "ConfigEditTime": new Date(),
            "ConfigItems": [
                {
                    "CPTClassIDS": arrCptClassIDs,
                    "CPTIDS": _n
                },
                {"Styles": arrStyles}
            ]
        };
        var guid = G_Cookie.getGuid();
        var jsonStr = JSON.stringify(jsonObj);
        var simulationExamRuleID = _gDistillTest.setConfigJson(appID, userID, jsonStr, '模拟考场', guid);
        jsonObj.SimulationExamRuleID = simulationExamRuleID;
        var ConfigJSON = JSON.stringify(jsonObj);
        _simulated = 1;
        _configClick(ConfigJSON, simulationExamRuleID);	//跳转进入做题界面
    }
	
	init();
})